package com.nl.controller.web.controller;

import java.io.IOException;
import java.io.InputStream;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.nl.controller.web.service.SmsQuerySentService;

import lombok.extern.slf4j.Slf4j;

@RestController
@Slf4j
@RequestMapping("smsQuerySent")
public class SmsQuerySentController {
	@Autowired
	private SmsQuerySentService smsQuerySentService;


	/**
	 * @author zhangh
	 * @Date 2019年9月9日13:48:22
	 * @
	 * @return
	 */
	@PostMapping("querySent")
	public JSON querySentInfo(
			HttpServletRequest request
			//@RequestParam(value = "taskId", required = true)String taskId
			){
		InputStream in;
		String reqJson="";
		JSONObject json2= new JSONObject();
		try {
			in = request.getInputStream();
			reqJson = IOUtils.toString(in, "utf-8");
			if (null == reqJson || "".equals(reqJson)) {
				json2.put("resultCode", "-1");
				json2.put("resultDesc", "失败");
				return json2;
			}
			JSONObject jsonObject = JSONObject.parseObject(reqJson);
			String taskId = jsonObject.getString("taskId");
			log.info("气象局发送量查询接口入参:"+reqJson);
			json2 = smsQuerySentService.querySentInfo(taskId);
		} catch (IOException e) {
			e.printStackTrace();
			log.error(e.toString());
		}
//		log.info(taskId);
//		if (null == taskId || "".equals(taskId)) {
//			json2.put("resultCode", "-1");
//			json2.put("resultDesc", "失败");
//			return json2;
//		}
//		json2 = smsQuerySentService.querySentInfo(taskId);
		log.info("气象局发送量查询接口回参:"+json2);
		return json2;

	}
}
